﻿using EfInfra;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace EfClient
{
    public static class DI
    {
        public static IServiceProvider InsProvider { get; private set; }

        static DI()
        {
            Configure();
        }

        private static void Configure()
        {
            var services = new ServiceCollection();

            //services.AddDbContext<OneToManyContext>((opt) =>
            //{
            //    string connStr= "Host=127.0.0.1;Port=5432;Database=eflearn;User ID=postgres;Password=sa*123;Pooling=true;MinPoolSize=10;MaxPoolSize=50;";
            //    opt.UseNpgsql(connStr);
            //    opt.LogTo(Console.WriteLine)
            //    .EnableSensitiveDataLogging();
            //});

            services.AddDbContext<MyContext>((opt) =>
            {
                string connStr = "Host=127.0.0.1;Port=5432;Database=eflearn;User ID=postgres;Password=sa*123;Pooling=true;MinPoolSize=10;MaxPoolSize=50;";
                opt.UseNpgsql(connStr);
                opt.LogTo(Console.WriteLine)
                .EnableSensitiveDataLogging();
            });

            InsProvider = services.BuildServiceProvider();
        }
    }
}